<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>基础数据管理</title>
    <jsp:include page="../../../head.jsp"/>
</head>
<script type="text/javascript">
    var pid = "${parentId}";
    var formSetting = {
        title: "查询基础数据",
        module: 'query',
        columns: [{
            name: "chn",
            label: "中文名",
            validate: 'validate[required]'
        }, {
            name: "en",
            label: "英文名"
        }, {
            name: "identifier",
            label: "标识符"
        }, {
            name: "use_state",
            label: "使用状态",
            type: "dropdown",
            data: [["启用", "0"], ["未启用", "1"]],
            op: 'eq'
        }],
        buttons: {
            custom: [
                {
                    id: "addbtn",
                    value: "添加数据",
                    click: function () {
                        $('#center', window.parent.document)
                                .attr(
                                        "src",
                                        "sysval-add?parentId="
                                        + pid);
                    }
                },
                {
                    id: "updateBtn",
                    value: "修改",
                    click: function () {
                        var id = $("#sysvalGrid").jqGrid("getGridParam",
                                                         "selrow");
                        if (id) {
                            $('#center', window.parent.document).attr(
                                    "src",
                                    "sysval-add?id=" + id + "&parentId="
                                    + pid);
                        } else {
                            alert("请点击需要修改的数据!");
                        }
                    }
                },
                {
                    id: "delbtn",
                    value: "删除",
                    click: function () {
                        if (confirm("确定要删除选择的项?")) {
                            var selectedIds = $("#sysvalGrid").jqGrid(
                                    "getGridParam", "selarrrow");
                            var data = "id=" + selectedIds;
                            $.ajax({
                                       url: "sysval-del",
                                       dataType: "json",
                                       data: data,
                                       success: function (data) {
                                           var msg = $.parseJSON(data.msg);
                                           if (msg.state == "1") {
                                               $("#sysvalGrid").jqGrid("setGridParam",
                                                                       {
                                                                           search: true
                                                                           // 将jqGrid的search选项设为true
                                                                       }).trigger("reloadGrid", [{
                                                   page: 1
                                               }]);
                                               jw.alert(msg.msg);
                                           } else {
                                               jw.alert(msg.msg);

                                           }
                                       }
                                   });
                        }
                    }
                }]
        },
        grid: {
            id: "sysvalGrid",
            title: "基础数据",
            url: "sysval-gridData",
            multiselect: true,
            postData: {
                "pid": pid
            },
            colModel: [{
                index: "id",
                name: "id",
                hidden: true
            }, {
                index: "chn",
                name: "chn",
                label: "中文名"
            }, {
                index: "en",
                name: "en",
                label: "英文名"
            }, {
                index: "identifier",
                name: "identifier",
                label: "标识符"
            }, {
                index: "use_state",
                name: "use_state",
                label: "使用状态",
                formatter: function (cellvalue, options, rowObject) {
                    if (cellvalue == "0") {
                        return "启用";
                    } else {
                        return "禁用";
                    }
                }
            }, {
                index: "updateUser",
                name: "updateUser",
                label: "修改人"
            }, {
                index: "updateDate",
                name: "updateDate",
                label: "修改时间"
            }]
        }
    };
    $(document).ready(function () {
        $("#baseValueTable").mrdForm(formSetting);
    });
</script>
<body>
<div id="baseValueTable"></div>
</body>
</html>
